<template>
  <div class="dashboard-container">
    <div class="welcome-section">
      <h2>欢迎使用智学云帆教学管理系统</h2>
      <p>{{ currentTime }}</p>
    </div>
    
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <template #header>
            <div class="card-header">
              <span>部门总数</span>
              <el-icon><OfficeBuilding /></el-icon>
            </div>
          </template>
          <div class="card-number">{{ stats.deptCount || 0 }}</div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <template #header>
            <div class="card-header">
              <span>员工总数</span>
              <el-icon><User /></el-icon>
            </div>
          </template>
          <div class="card-number">{{ stats.empCount || 0 }}</div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { OfficeBuilding, User } from '@element-plus/icons-vue'

const stats = ref({
  deptCount: 0,
  empCount: 0
})

const currentTime = ref('')
let timer = null

// 更新当前时间
const updateTime = () => {
  const now = new Date()
  const year = now.getFullYear()
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const hours = String(now.getHours()).padStart(2, '0')
  const minutes = String(now.getMinutes()).padStart(2, '0')
  const seconds = String(now.getSeconds()).padStart(2, '0')
  const week = ['日', '一', '二', '三', '四', '五', '六'][now.getDay()]
  
  currentTime.value = `${year}年${month}月${day}日 星期${week} ${hours}:${minutes}:${seconds}`
}

onMounted(() => {
  // 初始化时间
  updateTime()
  // 每秒更新一次时间
  timer = setInterval(updateTime, 1000)
})

onUnmounted(() => {
  // 组件销毁时清除定时器
  if (timer) {
    clearInterval(timer)
  }
})
</script>

<style scoped>
.dashboard-container {
  padding: 20px;
}

.welcome-section {
  margin-bottom: 30px;
  text-align: center;
}

.welcome-section h2 {
  font-size: 24px;
  color: #303133;
  margin-bottom: 10px;
}

.welcome-section p {
  font-size: 16px;
  color: #606266;
}

.data-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  color: #303133;
}

.card-number {
  font-size: 28px;
  font-weight: bold;
  color: #409EFF;
  text-align: center;
  padding: 20px 0;
}
</style> 